package collection;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
/**
 * JDK1.5之后推出的另一个特性:增强型for循环
 * 它不是用来取代传统for循环的工作，而是用来遍历集合或数组的
 * 语法:
 * for(元素类型 变量名 : 集合或数组){
 *     ...
 * }
 */
public class NewForDemo {
    public static void main(String[] args) {
        String[] array = {"one","two","three","four","five"};
        for (int i = 0;i<array.length;i++){
            String e = array[i];
            System.out.println(e);
        }
        for (String e : array){
            System.out.println(e);
        }
        Collection<String> c = new ArrayList<>();
        c.add("一");
        c.add("二");
        c.add("三");
        c.add("四");
        c.add("五");
        Iterator<String> it = c.iterator();
        while (it.hasNext()){
            String e = it.next();
            System.out.println(e);
        }
        for (String e : c){
            System.out.println(e);
        }
    }
}
